<?php
	$query = "select * from `radio_dj` where `userid`='$id'";
	$result = mysql_query($query);
	if (mysql_num_rows($result)) {
		$djprofile = mysql_fetch_array($result);
		$dj_id = $djprofile['id'];

			if ($_REQUEST['add']){
				$text = text2html(escapestr($_REQUEST["text"]));
				$query = "INSERT INTO radio_news (`lang`,`text`,`time`) VALUES ('$lang','$text','".time()."')";
				$result = mysql_query($query);
				if ($result) {
					$SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_news"),GetLangString($lang,"msg_newsadded"));
				} else {	
					$SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_error"),GetLangString($lang,"msg_dberror"));
				}
			} else  
		if ($_REQUEST['delete']){
			$deleteme=escapestr($_REQUEST['delete']);
			$query = "DELETE from `radio_news` where `id`='$deleteme'";
			$result = mysql_query($query);		
			if ($result) {
				$SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_news"),GetLangString($lang,"msg_newsdeleted"));
			} else {	
				$SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_error"),GetLangString($lang,"msg_dberror"));
				}
			}
			$query = "Select * from `radio_news` where `lang`='$lang'";
			$result 		=	 mysql_query($query);
			if (mysql_num_rows($result)) {
				while ($news = mysql_fetch_assoc($result)){
					$time = str_ireplace("%datetime%",date("d-m-Y H:i:s",$news['time']),GetLangString($lang,"txt_newsadded"));
					$sitenews = FormatSmallElement( $time . "   -   ".
					"<a href=\"index.php?do=djnews&delete=".$news['id']."\">".GetLangString($lang,"txt_delete")."</a>"
					, $news['text'] ) . $sitenews;
				}
			}	

			$SITE_MIDDLE .= FormatElement( GetLangString ($lang, "txt_news") , bb2html($sitenews) ) ;
	
			$ADDNEWS = '<form method="POST" ACTION="index.php?do=djnews">';
			$ADDNEWS .= '<textarea name="text" rows="5"></textarea>';
			$ADDNEWS .= "<input value=\"".GetLangString($lang,"txt_save")."\"	name = \"add\" 	type=\"submit\">" ;
			$ADDNEWS .= '</form>';
			$SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_addnews"),$ADDNEWS);


	} else {
		$SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_error"),GetLangString($lang,"msg_nodjerror"));
	} 
?>


